home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.618 < prev    next >
Text File  |  1992-02-06  |  3KB  |  98 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f0\fmodern Courier;}
  2. \paperw12920
  3. \paperh9520
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 Appkit Window\
  8. \
  9. Q:  In Version 2.0,  I am using the new Windows submenu. For each new window document that I create in my app, a new menu cell is added to the submenu with the window title and a small X at the left-most edge of the menu cell.  How do I programmatically control this X to make it broken when the document associated with the menu cell has been changed?\
  10. \
  11. A:  The window method 
  12. \f0\fs24 setDocEdited: (BOOL)flag 
  13. \f2\fs28 is responsible for displaying the broken X when it is set to YES.  This method controls both the X in the menu cell, and the X on the upper right corner of the window.  It has to be reset to NO 
  14. \b before saving the document
  15. \b0 , so that the X reappears as non-broken. See the code snippet below:\
  16. \
  17.  
  18. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\fs24\fc0 \
  19. /* In the case of a text object for example,this text delegate method is     responsible for notifying that the document has changed. Please note that ruler and font changes as well as changes caused by spell checking the Text are not reflected by this text delegate method.\
  20. */\
  21. \
  22. - textDidChange: sender\
  23. \{\
  24.     [currentDocWindow setDocEdited:YES];\
  25.     return self;\
  26. \}\
  27. \
  28.  
  29. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600     
  30. \f2\fs28 \
  31.  
  32. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\fs24\fc0 \
  33. \
  34. /*     Remember to reset setDocEdited to NO
  35. \b  before saving 
  36. \b0 your file, so that the X     shows as a regular X 
  37. \b when reading the file back in.
  38. \b0 \
  39. */\
  40. \
  41. - saveFilename:(const char *)filename\
  42. \{\
  43.     [currentDocWindow setDocEdited:NO];\
  44.     \
  45.     /* To generate a textDidChange message */\
  46.     [currentDocWindow makeFirstResponder:currentDocWindow]; \
  47.     ........\
  48.     return self;\
  49. \}\
  50. \
  51. \
  52. /*     After setting setDocEdited to YES, the state of isDocEdited is YES. You can\
  53.     query this state and, if appropriate, display an alert panel before the window\
  54.     closes.  Note the use of NXStringTable here for ease of localization. Please \
  55.     refer to our user interface guidelines and 2.0 release notes for more details.\
  56.     \
  57. */\
  58. \
  59. #define    SAVE    NX_ALERTDEFAULT\
  60. #define    CLOSE    NX_ALERTALTERNATE\
  61. #define    CANCEL    NX_ALERTOTHER\
  62. \
  63. - windowWillClose:sender\
  64. \{\
  65.     int result;\
  66.     \
  67.     if ([currentDocWindow isDocEdited]) \{\
  68.         if (!stringTable)\
  69.             stringTable = [[NXApp delegate] stringTable];\
  70.         result = NXRunAlertPanel([NXApp appName],\
  71.             [stringTable valueForStringKey:\
  72.             "The document %s has unsaved changes.\\nClose anyway?"],\
  73.             [stringTable valueForStringKey:"Save"],\
  74.             [stringTable valueForStringKey:"Close"],\
  75.             [stringTable valueForStringKey:"Cancel"],\
  76.             [currentDocWindow title]);\
  77.         switch(result) \{\
  78.             case SAVE:\
  79.                 ...\
  80.                 break;\
  81.             case CLOSE:\
  82.                 break;\
  83.             case CANCEL: \
  84.                 return nil;\
  85.             \}\
  86.         \}\
  87.     \
  88.     ......\
  89.     \
  90.     return self;\
  91. \}\
  92. \
  93. \
  94.  
  95. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\fs28 QA618\
  96. \
  97.  
  98.